package com.test.jogl;

import javax.media.opengl.GL;

public class Octogone {
   public static void octogone(GL gl, float initX, float initY, float edge) {
      float hexCos = (float) Math.cos(135.0);
      float hexSin = (float) Math.sin(135.0);
      float x1, y1;
      float x2, y2;
      float x3, y3;
      float x4, y4;
      float x5, y5;
      float x6, y6;
      float x7, y7;
      float x8, y8;
      float z = 0.0f;

      gl.glShadeModel(GL.GL_FLAT);
      gl.glNormal3f(0.0f, 0.0f, 1.0f);

      gl.glBegin(GL.GL_POLYGON);

      x1 = initX;
      y1 = initY;
      gl.glVertex3f(x1, y1, z);
      System.out.println("x1: " + x1 + "\ty1: " + y1);

      x2 = x1 + edge;
      y2 = y1;
      gl.glVertex3f(x2, y2, z);
      System.out.println("x2: " + x2 + "\ty2: " + y2);

      x3 = x2 + hexCos * edge;
      y3 = hexSin * edge;
      gl.glVertex3f(x3, y3, z);
      System.out.println("x3: " + x3 + "\ty3: " + y3);

      x4 = x3;
      y4 = y3 + edge;
      gl.glVertex3f(x4, y4, z);
      System.out.println("x4: " + x4 + "\ty4: " + y4);

      x5 = x2;
      y5 = y4 + y3;
      gl.glVertex3f(x5, y5, z);
      System.out.println("x5: " + x5 + "\ty5: " + y5);

      x6 = x1;
      y6 = y5;
      gl.glVertex3f(x6, y6, z);
      System.out.println("x6: " + x6 + "\ty6: " + y6);

      x7 = x1 - (x3 - x2);
      y7 = y4;
      gl.glVertex3f(x7, y7, z);
      System.out.println("x7: " + x7 + "\ty7: " + y7);

      x8 = x7;
      y8 = y3;
      gl.glVertex3f(x8, y8, z);
      System.out.println("x8: " + x8 + "\ty8: " + y8);
      gl.glEnd();
   }
}
